<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>JSON.stringify()</title>
</head>

<body>
    <script>
        //  JSON.stringify(object [,replacer [,space] ] )方法
        //  replacer：参数过滤器为数组时，结果只包含数组中列出的属性
        var person = {
            name: "小明",
            age: 18,
            hobby: ["swimming", "sing", "basketball"],
            date: 2000,
            year: undefined
        };
        
        //第2个参数，为过滤器,参数过滤器为数组时，
        //输出结果对象只包含数组中列出的属性
        
        var people = JSON.stringify(person, ["name", "year"]); //{"name":"小明"}
        //var people = JSON.stringify(person,["name","age","hobby"]);
        // //{"name":"小明","age":18,"hobby":["swimming","sing","basketball"]}
        console.log(people);
    </script>
</body>

</html>